﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.IO;
using System.Text;

public partial class Admin_kcgl_stuinfo2 : System.Web.UI.Page
{
    DataClassesDataContext db = new DataClassesDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }
    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lb1 = (Label)e.Row.Cells[0].FindControl("Label1");
            lb1.Text = (GridView2.PageIndex * GridView2.PageSize + e.Row.RowIndex + 1).ToString();
        }
    }
    private void BindData()
    {
        int subjectNo = Convert.ToInt32(Request.QueryString["subjectNo"].ToString());
        //int s = Convert.ToInt32(Request.QueryString["classNo"].ToString()); 
        //Response.Write(s);
        string classNo = Request.QueryString["classNo"];
        string examName = Request.QueryString["place"];
        var SchRes = (from p in db.proc_GetBkgxNowYear()
                      select p).ToList().First();
        Label1.Text = SchRes.schoolName;
        Label2.Text = SchRes.dYear;
        Label3.Text = classNo + "(" + examName + ")";

        var ExamStuRes = from p in db.proc_GetExamStuInfoBySubjectNoClassNo(subjectNo, classNo)
                         select p;
        GridView2.DataSource = ExamStuRes;
        GridView2.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("ExamInfo.aspx");
    }
    protected void Button2_Click(object sender, EventArgs e)    //导出Excel
    {
        GridView2.AllowPaging = false;
        //撤销分页后绑定所有数据
        BindData();
        //导出到Excel
        string style = @"<style> .text { mso-number-format:\@; } </script> ";
        Response.ClearContent();
        Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
        Response.ContentType = "application/excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        GridView2.RenderControl(htw);
        Response.Write(style);
        Response.Write(sw.ToString());
        Response.End();
        //导出后恢复分页
        GridView2.AllowPaging = true;
        //重新绑定
        BindData();
    }
    protected void Button3_Click(object sender, EventArgs e)   //打印门贴
    {
        int subjectNo = Convert.ToInt32(Request.QueryString["subjectNo"].ToString());
        string classNo = Request.QueryString["classNo"].ToString();
        string Url = "dykcmt.aspx?subjectNo=" + subjectNo + "&classNo=" + classNo;
        Response.Redirect(Url);
    }
    protected void Button4_Click(object sender, EventArgs e)  //打印学生名册
    {
        int subjectNo = Convert.ToInt32(Request.QueryString["subjectNo"].ToString());
        string classNo = Request.QueryString["classNo"].ToString();
        string examName = Request.QueryString["place"].ToString();
        string Url = "dyxsmc.aspx?subjectNo=" + subjectNo + "&classNo=" + classNo + "&place=" + examName;
        Response.Redirect(Url);
    }
    protected void Button5_Click(object sender, EventArgs e)   //打印考场信息核对表
    {
        int subjectNo = Convert.ToInt32(Request.QueryString["subjectNo"].ToString());
        string classNo = Request.QueryString["classNo"].ToString();
        string examName = Request.QueryString["place"].ToString();
        string Url = "dykcxxhdb.aspx?subjectNo=" + subjectNo + "&classNo=" + classNo + "&place=" + examName;
        Response.Redirect(Url);
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
        // Confirms that an HtmlForm control is rendered for
        //为了保险期间还可以在这里加入判断条件防止HTML中已经存在该ID
    }
}